package com.example.freemarker.utils;

import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.util.List;

/**
 * @Classname GetPage
 * @Description TODO
 * @Date 2022/8/7 20:53
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class GetPage implements TemplateMethodModelEx {

    @Override
    public Object exec(List arguments) throws TemplateModelException {
        if(arguments.size() < 2){
            throw new TemplateModelException("参数不得小于两个");
        }
        int total=Integer.parseInt(String.valueOf(arguments.get(0)));
        int size = Integer.parseInt(String.valueOf(arguments.get(1)));
        int page= total/size;
        if(total==0){
            page=1;
        }else if(total % size !=0){
            page++;
        }
        return page;
    }
}
